Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update HttpSemanticConventions for Instrumentation.Http (part2) #4639

Merged
merged 21 commits into from
Jul 13, 2023
Merged

update HttpSemanticConventions for Instrumentation.Http (part2) #4639

merged 21 commits into from
Jul 13, 2023

Conversation

TimothyMothra
Copy link
Contributor

@TimothyMothra TimothyMothra commented Jul 6, 2023

Design discussion issue #4484
Follow up to #4538

Previous PR updated Net Core implementation.
This PR makes the same changes for Net Fx.

Changes

  • update Instrumentation.Http HttpWebRequestActivitySource.netfx.cs to emit new attributes
    • http.method -> htttp.request.method
    • net.peer.name -> server.address
    • net.peer.port ->server.port
    • http.scheme -> REMOVED
    • http.url -> url.full
    • http.flavor -> network.protocol.version
    • http.status.code -> http.response.status.code
  • remove "url.scheme" from other classes.
    This was introduced in the previous PR. This is for server spans only, not client.
  • Updated tests. This class was large, so I copied the original test class to make it easier to separate the scenarios.
    For review, pay attention to the helper methods at the bottom of the class near Line 200 VerifyActivityStartTags() and VerifyActivityStopTags()
    • Added HttpWebRequestActivitySourceTestsNew.netfx.cs to test the new attributes.
      This class can replace HttpWebRequestActivitySourceTests.netfx.cs when this library is GA.
    • Added HttpWebRequestActivitySourceTestsDupe.netfx.cs to test emitting both new and old attributes.
      This class can be deleted when this library is GA.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@TimothyMothra TimothyMothra requested a review from a team July 6, 2023 20:34
@codecov
Copy link

codecov bot commented Jul 7, 2023

Codecov Report

Merging #4639 (36475e2) into main (d2b269a) will increase coverage by 0.04%.
The diff coverage is 96.55%.

❗ Current head 36475e2 differs from pull request most recent head 743a311. Consider uploading reports for the commit 743a311 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4639      +/-   ##
==========================================
+ Coverage   84.94%   84.99%   +0.04%     
==========================================
  Files         314      314              
  Lines       12689    12706      +17     
==========================================
+ Hits        10779    10799      +20     
+ Misses       1910     1907       -3     
Impacted Files Coverage Δ
...tp/Implementation/HttpHandlerDiagnosticListener.cs 68.42% <ø> (+0.59%) ⬆️
...ementation/HttpHandlerMetricsDiagnosticListener.cs 75.75% <ø> (+2.22%) ⬆️
...plementation/HttpWebRequestActivitySource.netfx.cs 80.86% <96.55%> (+0.62%) ⬆️

... and 6 files with indirect coverage changes

Copy link
Member

@vishweshbankwar vishweshbankwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +796 to +830
private static void VerifyActivityStartTags(string netPeerName, int? netPeerPort, string method, string url, Activity activity)
{
// New
Assert.NotNull(activity.TagObjects);
Assert.Equal(method, activity.GetTagValue(SemanticConventions.AttributeHttpRequestMethod));
if (netPeerPort != null)
{
Assert.Equal(netPeerPort, activity.GetTagValue(SemanticConventions.AttributeServerPort));
}

Assert.Equal(netPeerName, activity.GetTagValue(SemanticConventions.AttributeServerAddress));

Assert.Equal(url, activity.GetTagValue(SemanticConventions.AttributeUrlFull));

// Old
Assert.NotNull(activity.TagObjects);
Assert.Equal(method, activity.GetTagValue(SemanticConventions.AttributeHttpMethod));
if (netPeerPort != null)
{
Assert.Equal(netPeerPort, activity.GetTagValue(SemanticConventions.AttributeNetPeerPort));
}

Assert.Equal(netPeerName, activity.GetTagValue(SemanticConventions.AttributeNetPeerName));

Assert.Equal(url, activity.GetTagValue(SemanticConventions.AttributeHttpUrl));
}

private static void VerifyActivityStopTags(int statusCode, Activity activity)
{
// New
Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpResponseStatusCode));

// Old
Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the new validation methods

Comment on lines +796 to +813
private static void VerifyActivityStartTags(string netPeerName, int? netPeerPort, string method, string url, Activity activity)
{
Assert.NotNull(activity.TagObjects);
Assert.Equal(method, activity.GetTagValue(SemanticConventions.AttributeHttpRequestMethod));
if (netPeerPort != null)
{
Assert.Equal(netPeerPort, activity.GetTagValue(SemanticConventions.AttributeServerPort));
}

Assert.Equal(netPeerName, activity.GetTagValue(SemanticConventions.AttributeServerAddress));

Assert.Equal(url, activity.GetTagValue(SemanticConventions.AttributeUrlFull));
}

private static void VerifyActivityStopTags(int statusCode, Activity activity)
{
Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpResponseStatusCode));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the new validation methods

Copy link
Contributor

@utpilla utpilla Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the entire test file doesn't look right. We really only need to test the new/dupe attributes for just the happy-path scenario. Could you check the attributes only for the happy-path case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same approach we took for the AspNetCore library.

I can work on a new test that just evaluates the happy-path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need more time for this. The attribute changes affect 3 different methods and there's not one test scenario that calls all three. I should have new tests by the end of today (Wed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate class is going to be necessary.
I tried adding a new test to the existing class, but because this is working with static objects, it breaks the other tests in this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with Utkarsh, going to keep the separate test classes to avoid impacting the existing tests.
New classes will scope down to a single test.

activity.SetTag(SemanticConventions.AttributeNetPeerName, request.RequestUri.Host);
if (!request.RequestUri.IsDefaultPort)
// see the spec https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md
if (Options.HttpSemanticConvention.HasFlag(HttpSemanticConvention.Old))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be extracted into boolean variables to avoid checking them repeatedly. This can be done in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern used in the other libraries won't work here because this is a static class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'm not sure why this class uses a static instance of the options.

However, you should still be able to extract them into static bool variables in this case and use them instead of checking if the enum has a flag repeatedly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just a static instance of the options, the entire class is static.

I changed the Options field to a property so I can use the setter to evaluate the booleans in this commit: b91509e

@utpilla
Copy link
Contributor

utpilla commented Jul 12, 2023

Need to update the existing CHANGELOG entry with this PR. It looks like we missed to add the previous PR in the CHANGELOG entry:

* Updated [Http Semantic Conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/trace/semantic_conventions/http.md).
This library can emit either old, new, or both attributes. Users can control
which attributes are emitted by setting the environment variable
`OTEL_SEMCONV_STABILITY_OPT_IN`.

@TimothyMothra
Copy link
Contributor Author

I've corrected the links to the spec (new repo) in all comments and changelog.
Please re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants